{template 'header'}
<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="x-red">*</span>公告标题
            </label>
            <div class="layui-input-block">
                <input type="text" id="title" name="title" required="" lay-verify="title"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">
                <span class="x-red"></span>公告内容
            </label>
            <div class="layui-input-block">
                <textarea name="content" placeholder="请输入内容" class="layui-textarea" lay-verify="content"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 2) {
                    return '公告标题至少得2个字符啊';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            //发异步，把数据提交给php
            var url = '{php echo $this->createWebUrl("notice_list",array("op"=>"add"))}'
            $.post(url, data.field, function (ret) {
                if (ret.code) {
                    layer.alert("增加成功", {icon: 6}, function () {
                        //关闭当前frame
                        x_admin_close();

                        // 可以对父窗口进行刷新
                        x_admin_father_reload();
                    });
                } else {
                    layer.msg(ret.msg, {icon: 0});
                }
            }, 'json')

            return false;
        });


    });
</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>